package com.example.androidstudy.activity;

import com.example.androidstudy.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Redirect_GetResultActivity extends Activity {
	protected static final int GET_CODE = 0;
	Button button;
	TextView tv_display;
	Intent intent;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.redirect_main);
		button = (Button) findViewById(R.id.bt_getResult);
		button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				intent = new Intent(Redirect_GetResultActivity.this, ResultReturnActivity.class);
				startActivityForResult(intent, GET_CODE);
				
			}
		});
		tv_display = (TextView) findViewById(R.id.tv_result);
		
	}
	
	

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(requestCode == GET_CODE){
			if(resultCode == RESULT_CANCELED){
				tv_display.append("Cancel!");
				tv_display.append("\n");
			}else{
				tv_display.append("Result: ");
				tv_display.append(String.valueOf(resultCode)+" - ");
				if(data!=null){
					tv_display.append(data.getAction());
					tv_display.append("\n");
				}
			}
		}
	}



	@Override
	protected void onDestroy() {
		super.onDestroy();
		finish();
	}
	
}
